package com.king.juc.n8.jucdemo.readwritelock;

import static com.king.juc.utils.ThreadUtil.sleep;

/**
 * 读写锁测试
 *  读-读: 可以并发
 *  读-写/写-写: 互斥
 * @author king
 * @date 2020/12/12 22:17
 */
public class ReadWriteLockTest {
    public static void main(String[] args) {
        DataContainer dataContainer = new DataContainer();
        new Thread(() -> {
            dataContainer.read();
        }, "t1").start();

        new Thread(() -> {
            dataContainer.read();
        }, "t2").start();

        sleep(1);
        new Thread(() -> {
            dataContainer.write();
        }, "t3").start();
    }
}
